import numpy as np
from typing import List
from scipy import stats

def extract_features(sensor_readings: List[List[float]]) -> np.ndarray:
    """
    从传感器数据中提取特征
    
    特征包括：
    1. 每个传感器的均值
    2. 每个传感器的标准差
    3. 每个传感器的最大值
    4. 每个传感器的最小值
    5. 每个传感器的峰峰值
    6. 每个传感器的偏度
    7. 每个传感器的峰度
    """
    data = np.array(sensor_readings)
    
    # 确保数据形状正确 (时间点数量 x 传感器数量)
    if len(data.shape) != 2:
        raise ValueError("传感器数据必须是二维数组")
    
    features = []
    
    # 对每个传感器通道计算特征
    for sensor_idx in range(data.shape[1]):
        sensor_data = data[:, sensor_idx]
        
        # 计算统计特征
        mean = np.mean(sensor_data)
        std = np.std(sensor_data)
        max_val = np.max(sensor_data)
        min_val = np.min(sensor_data)
        peak_to_peak = max_val - min_val
        skewness = stats.skew(sensor_data)
        kurtosis = stats.kurtosis(sensor_data)
        
        # 添加特征
        features.extend([mean, std, max_val, min_val, peak_to_peak, skewness, kurtosis])
    
    return np.array(features) 